import React from 'react';
import { Form, Table } from 'antd';

const TYPE_MAP = {
    1: {
        point: '工作结果',
        info: '结果不通过不超过次数'
    },
    2: {
        point: '工作时效性',
        info: '逾期不超过次数'
    },
    3: {
        point: '工作饱和度',
        info: '不低于部门平均饱和度百分比'
    }
};

const renderStr = (text, record) => (
    <>
        {text}
        {record.type === 3 ? '%' : '次'}
    </>
);

const ResultDetail = ({ data, ...rest }) => {
    const { taskAssessVO } = data || {};
    const { detail = [] } = taskAssessVO || {};

    const columns = [
        {
            title: '类型',
            dataIndex: 'point'
        },
        {
            title: '考核条件',
            dataIndex: 'info'
        },
        {
            title: '周评考核标准',
            dataIndex: 'weekValue',
            render: renderStr
        },
        {
            title: '月评考核标准',
            dataIndex: 'monthValue',
            render: renderStr
        },
        {
            title: '季评考核标准',
            dataIndex: 'quarterValue',
            render: renderStr
        }
    ];

    const getFinalList = () =>
        detail.map(item => ({
            ...item,
            ...TYPE_MAP[item.type]
        }));

    return (
        <Form {...rest}>
            <Form.Item label="任务要求">
                考评周期间被分配任务明细存在
                {typeof taskAssessVO?.requirementsCount !== 'undefined' ? taskAssessVO?.requirementsCount : '--'}
                项不符合时，则为不合格
            </Form.Item>
            <Form.Item label="任务考核">
                <Table
                    rowKey="type"
                    columns={columns}
                    dataSource={getFinalList() || []}
                    pagination={false}
                    scroll={{ x: 'max-content' }}
                />
            </Form.Item>
            <Form.Item label="任务指标说明">{taskAssessVO?.instructions || '--'}</Form.Item>
        </Form>
    );
};

export default ResultDetail;
